package com.sto.stoapp.activity.administrator;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.adapter.LogFileListAdapter;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.file.LogFileListItem;
import com.sto.stoapp.log.ExceptionLog;
import com.sto.stoapp.widget.StoHomeActivity;

public class ExceptionLogListActivity extends StoHomeActivity {
	private ListView listView;

	private LogFileListAdapter mAdapter; // 文件列表适配器
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.exception_log_list);
		this.setTitleBottom(R.string.exception_log,
				HomeBroadAction.ADMINISTRATOR_BROAD);
		initWidget();
	}
	
	
	private void initWidget() {
		listView = (ListView) findViewById(R.id.log_file_list_select);
		
		mAdapter = new LogFileListAdapter(this, ExceptionLog.getInstance().getAllExceptionFile());
		listView.setAdapter(mAdapter);
		listView.setOnItemClickListener(itemClick);
		listView.requestFocus();
	}
	
	ListView.OnItemClickListener itemClick = new ListView.OnItemClickListener() {
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			int itemType = mAdapter.getItemType((int) id);
			if (itemType == LogFileListItem.TXT_FILE) { // 是文件
				Bundle bundle = new Bundle();
//				bundle.putString("FILE_PATH", new File(ExceptionLog.getInstance().getPath()).getPath()
//						+ "/" + mAdapter.getItem((int) id).name);
				bundle.putString("FILE_PATH",  mAdapter.getItem((int) id).fileName);
				Intent mIntent = new Intent(ExceptionLogListActivity.this,
						AdminExceptionLogActivity.class);
				mIntent.putExtras(bundle);
				startActivity(mIntent);
			} else {
				Toast.makeText(ExceptionLogListActivity.this, "不是文件",
						Toast.LENGTH_SHORT).show();
			}
		}
	};
	
	

	
	
}
